<?php
namespace app\api\controller;

use app\common\business\Goods as goodsBusi;
use app\common\lib\Show;
//use app\common\lib\Snowflake;
use think\facade\Log;
// 分类API
class Index extends ApiBase
{
	//获取首页论循图
	public function getRotationChart(){		
		$chart = (new goodsBusi())->getRotationChart();
		
		//halt($categorys);
		//return show(config('status.success'),'ok',$chart);
		return Show::success($chart);
	}

	// 推荐商品
	public function cagegoryGoodsRecommend(){
		$categoryIds = [
			31,32
		];
		$goods = (new goodsBusi())->categoryGoodsRecommend($categoryIds);
		return Show::success($goods);
	}

	public function get(){
		$result = [
         'status' => 1,
         'message' => '请求成功',
         'result' => [
            'id' =>1  
         ], 
        ];
        return Show::success($result);
        //return json_encode($result);
		//exit;
		//$res = (new \app\common\business\Order)->updateOrderStatus();
		//$arr = json_decode($res,true);
		//echo '<pre>';print_r($arr);
		//(new \app\common\business\Order)->checkOrderStatus();
		echo 'hello'.PHP_EOL;
		exit;
		echo "<img src='http://www.fresh.com:8082/upload/image/20200603/9c29118923fde1f6844319382227aa9c.jpg' height='400' width='400' />";
		Log::write(date('Y-m-d H:i:s',time()).' 日拱一卒 每天进步一点 多思考 多总结');
		exit;
		phpinfo();exit;
		//$snowflake = new \Godruoyi\Snowflake\Snowflake;
		$snowflake = new \app\common\lib\Snowflake;
		echo $snowflake->getInstance()->nextId();exit;

		/*
		$a=array(
		    array('key'=>'dfga','value'=>52),
		    array('key'=>'sag','value'=>42),
		    array('key'=>'garc','value'=>92),
		    array('key'=>'xfsa','value'=>82),
		    array('key'=>'afg','value'=>32)
		);
		dump($a);
		$arr = array_column($a, 'value');
		dump($arr);
		array_multisort($arr,SORT_DESC,$a);
		dump($a);
		*/
		$arr = array(
		    '0' => array(
		        'num1' => 3,
		        'num2' => 27 
		    ),
		    
		    '1' => array(
		        'num1' => 5,
		        'num2' => 50
		    ),
		    
		    '2' => array(
		        'num1' => 4,
		        'num2' => 44
		    ),
		    
		    '3' => array(
		        'num1' => 3,
		        'num2' => 78
		    ) 
		);
		foreach ($arr as $key => $value) {
			$num1[$key] = $value['num1'];
			//$num2[$key] = $value['num2'];
		}
		$num2 = array_column($arr, 'num2');
		dump($num1);
		dump($num2);
		array_multisort($num1,SORT_DESC,$num2,SORT_ASC,$arr);
		dump($arr);

	}
	/*
	public function bubbleSort($arr){
		$len = count($arr);
		$flag = 1;
		for($i=0;$i<$len-1;$i++){
			$flag = 1;
			for($j=0;$j<$len-1-$i;$j++){
				if($arr[$j]>$arr[$j+1]){
					$temp = $arr[$j];
					$arr[$j] = $arr[$j+1];
					$arr[$j+1] = $temp;
					$flag = 0;
				}
			}
			if($flag == 1){
				break;
			}
		}
	}

	class Single{
		private static $instance = null;
		private function __construct(){}
		private funcion __clone(){}
		public static function getInstance(){
			if(!self::$instance instanceof self){
				self::$instance = new self();
			}
			return self::$instance;
		} 
	}
	*/
}